package com.ruoyi.web.util;

import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;

/**
 * @author huangjie
 * @date 2025/11/11
 */



public class ChatUtil {

    private static ChatModel model;

    /**
     * 使用静态初始化块，为私有的静态成员变量model初始化值
     * 单例
     */
    static {
        model = OpenAiChatModel.builder()
                .baseUrl("https://api.deepseek.com")
                .apiKey("sk-3131e24caba04207a5972f46b37d2f60")
                .modelName("deepseek-chat")
                .build();
    }

    /**
     * 获取AIService代理对象
     * @param clazz
     * @return
     * @param <T>
     */
    public static <T> T getService(Class<T> clazz) {
        return AiServices.create(clazz, model);
    }
}